// pages/integral/order-express/order-express.ts
import { getIntegralOrderExpress } from '../../../api/points_mall.js';

Page({
  data: {
    orderId: '',
    orderInfo: {},
    expressInfo: {},
    loading: true
  },

  onLoad(options: any) {
    this.setData({ orderId: options.orderId });
    this.getExpressInfo();
  },

  // 获取物流信息
  async getExpressInfo() {
    try {
      this.setData({ loading: true });
      const res = await getIntegralOrderExpress(this.data.orderId);
      this.setData({
        orderInfo: res.data.order,
        expressInfo: res.data.express,
        loading: false
      });
    } catch (error) {
      console.error('获取物流信息失败:', error);
      wx.showToast({
        title: '获取物流信息失败',
        icon: 'none',
      });
      this.setData({ loading: false });
    }
  },

  // 复制快递单号
  copyExpressNumber() {
    wx.setClipboardData({
      data: this.data.orderInfo.delivery_id,
      success: () => {
        wx.showToast({
          title: '已复制',
          icon: 'success',
        });
      }
    });
  },

  // 刷新物流信息
  onRefresh() {
    this.getExpressInfo();
  }
});
